/**
 * calculator
 *
 * @author : tzy
 * @Date : 2021-03-16
 * @Description:
 **/

package com.tang.calculator.symbols;

import com.tang.calculator.context.CalculateContext;

import java.util.Stack;

public interface OperatorSymbol extends Symbol {
    public int getPriority();

    default void operate(CalculateContext context) {
        Stack<OperatorSymbol> operatorStack = context.getOperatorStack();
        while (!operatorStack.isEmpty() && operatorStack.peek().getPriority() >= this.getPriority()) {
            OperatorSymbol operatorSymbol = operatorStack.pop();
            operatorSymbol.simpleOperate(context);
        }
        operatorStack.push(this);
    }

    public void simpleOperate(CalculateContext context);
}
